package com.edmond.jyframe.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.edmond.jyframe.R;
import com.edmond.jyview.widget.JYFragmentPagerAdapter;

import java.util.ArrayList;

/**
 * Created by edmond on 17-4-24.
 */

public class ShowFragment extends Fragment {
    private View view = null;
    private TabLayout tabLayout = null;
    private ViewPager viewPager = null;

    private ArrayList<Fragment> fragments = new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_show,container,false);

        tabLayout = (TabLayout) view.findViewById(R.id.tab);
        viewPager = (ViewPager) view.findViewById(R.id.viewpager);

        fragments.add(new ShowOneFragment());
        fragments.add(new ShowTwoFragment());
        fragments.add(new ShowThirdFragment());

        viewPager.setAdapter(new JYFragmentPagerAdapter(getChildFragmentManager(),fragments));

        TabLayout.Tab tab1 = tabLayout.newTab();
        TabLayout.Tab tab2 = tabLayout.newTab();
        TabLayout.Tab tab3 = tabLayout.newTab();

        tab1.setText("dfds");
        tab2.setText("dfds");
        tab3.setText("dfds");

        tabLayout.addTab(tab1);
        tabLayout.addTab(tab2);
        tabLayout.addTab(tab3);

        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
        tabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager));

        return view;
    }
}
